package xrz.cuanbao.application;

import org.xutils.x;
import org.xutils.common.Callback.CommonCallback;
import org.xutils.http.RequestParams;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

public class CrashService extends Service {
	
	private int count = 0;
	String result;

	@Override
	public IBinder onBind(Intent arg0) {
		return null;
	}

	@Override
	public void onCreate() {
		super.onCreate();
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		try {
			upload(intent.getStringExtra("result"));
		} catch (Exception e) {
			// TODO: handle exception
		}
		return super.onStartCommand(intent, flags, startId);
	}

	private synchronized void upload(final String path) {
		if (path == null)
			return;
		
		RequestParams params = new RequestParams("http://115.28.57.216/tools/interface/SendLog.php");
		params.addBodyParameter("text", path);
		x.http().post(params, new CommonCallback<String>() {

			@Override
			public void onSuccess(String result) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onError(Throwable ex, boolean isOnCallback) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onCancelled(CancelledException cex) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onFinished() {
				// TODO Auto-generated method stub
				
			}
		});
	}
}
